home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / x / gui / x3d.lha / x3d / x3d.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-08  |  8.1 KB  |  320 lines

  1.  
  2. /*
  3.   Copyright 1992 Mark Spychalla
  4.  
  5.   Permission to use, copy, modify, distribute, and sell this software and
  6.   its documentation for any purpose is hereby granted without fee,
  7.   provided that the above copyright notice appear in all copies and that
  8.   both that copyright notice and this permission notice appear in
  9.   supporting documentation, and that the name of Mark Spychalla not be used
  10.   in advertising or publicity pertaining to distribution of the software
  11.   without specific, written prior permission.  Mark Spychalla makes no
  12.   representations about the suitability of this software for any purpose.
  13.   It is provided "as is" without express or implied warranty.
  14.  
  15.   Mark Spychalla disclaims all warranties with regard to this software,
  16.   including all implied warranties of merchantability and fitness, in no
  17.   event shall Mark Spychalla be liable for any special, indirect or
  18.   consequential damages or any damages whatsoever resulting from loss of use,
  19.   data or profits, whether in an action of contract, negligence or other
  20.   tortious action, arising out of or in connection with the use or performance
  21.   of this software.
  22. */
  23.  
  24.  
  25. /* Conditional compile for int math */
  26.  
  27. #ifdef USE_INTS
  28.  
  29. #define SHIFT    12 
  30. #define TRIG_ADJ    4096.0
  31. typedef int    number;
  32.  
  33. #else
  34.  
  35. #define TRIG_ADJ    1.0
  36. typedef float    number;
  37.  
  38. #endif 
  39.  
  40. /* Constants */
  41.  
  42.  
  43. #define RClipWithRight   6
  44. #define RClipWithLeft    5 
  45. #define PointBehind      4 
  46. #define BClipWithRight   3 
  47. #define BClipWithLeft    2 
  48. #define ClipWithRight    3 
  49. #define ClipWithLeft     2 
  50. #define ClipWithBottom   1 
  51. #define ClipWithTop      0 
  52.  
  53. #define RRight     (1 << RClipWithRight) 
  54. #define RLeft      (1 << RClipWithLeft) 
  55. #define Behind     (1 << PointBehind)  
  56. #define BRight     (1 << BClipWithRight) 
  57. #define BLeft      (1 << BClipWithLeft) 
  58. #define Right      (1 << ClipWithRight) 
  59. #define Left       (1 << ClipWithLeft) 
  60. #define Bottom     (1 << ClipWithBottom) 
  61. #define Top        (1 << ClipWithTop)  
  62. #define Bmask      (~BRight & ~BLeft) 
  63. #define Rmask      (~RRight & ~RLeft) 
  64. #define RBmask     (Rmask & Bmask) 
  65. #define RLeftRight (RRight | RLeft) 
  66. #define ALLmask    (RRight | RLeft | Behind | BRight | BLeft | Bottom | Top )
  67.  
  68. #define NUMBOUNDS     8
  69. #define NUMSTIPPLES     17
  70. #define MAXVALUE     6
  71. #define VALUESCALE     51
  72. #define MAXCOLORDIST    (443.40501)
  73. #define STIPPLESIZE     4
  74. #define BITSPERBYTE     8
  75. #define MAXCOLORS    256
  76. #define MAXLINE        8192
  77. #define MAXOPTIONLEN    256
  78. #define TMPSTRLEN       16
  79. #define SMALLMOVEMENT   40000
  80. #define POINTERRATIO    0.007 
  81. #define MARGIN          30
  82. #define TWOPI        6.2831853
  83. #define REQUESTFACTOR   3
  84. #define EIGHTBIT    8
  85. #define POSTSCRIPT      0
  86. #define HPGL        1
  87. #define HELPLINES       40
  88.  
  89. #define MAXSTACK    100
  90. #define STOP        10
  91.  
  92. #define EOK        0
  93. #define ERROR        -1
  94.  
  95. #define FONT         "9x15"
  96. #define TITLEFONT    "12x24"
  97. #define BOLDFONT     "9x15bold"
  98. #define FIXED        "fixed"
  99.  
  100. #define LONGESTSTRING "     ROTATE OBJECT ABOUT Z   Horizontal   "
  101.  
  102. /* Color Modes */
  103.  
  104. #define BW    1   
  105. #define STEREO    2  
  106. #define COLOR    3  
  107.  
  108. /* Rendering modes */
  109.  
  110. #define WIREFRAME     1
  111. #define HIDDENLINE    2
  112. #define SOLID        3
  113.  
  114. /* Supported Depths */
  115.  
  116. #define ONE         1
  117. #define EIGHT        8
  118. #define TWENTYFOUR    24
  119.  
  120. /* Double buffering constants */
  121.  
  122. #define MAX_COLORS         232
  123. #define BUFFER_CMAP         11
  124. #define BUFFER0             240
  125. #define BUFFER1             15 
  126.  
  127. /* Segment intersection constants */
  128.  
  129. #define ENDS_INTERSECT   3
  130. #define SAME             2
  131. #define ABOVE            1
  132. #define INTERSECT        0
  133. #define BELOW           -1
  134.  
  135. /* x3d macros */
  136.  
  137.  
  138. #define clipWithBottom(x,y,dx,dy,V)    { x -= ((dx * (V+y)) / dy); y = -V; }
  139. #define clipWithTop(x,y,dx,dy,V)       { x += ((dx * (V-y)) / dy); y =  V; }
  140. #define clipWithLeftSide(x,y,dx,dy,H)  { y -= ((dy * (H+x)) / dx); x = -H; }
  141. #define clipWithRightSide(x,y,dx,dy,H) { y += ((dy * (H-x)) / dx); x =  H; }
  142.  
  143. #define FONTHEIGHT(font) (font->ascent + font->descent)
  144.  
  145. #define HelpPrint(g, x, y, string){                                        \
  146.    XDrawString(g->dpy, g->helpWin, g->helpGc, x, y, string, strlen(string)); \
  147.    y += FONTHEIGHT(g->font);                                               \
  148. }
  149.  
  150. #define swapPtrs(ptr1, ptr2)                                         \
  151.        ptr1 = (polygon **)((long)ptr1 ^ (long)ptr2);                 \
  152.        ptr2 = (polygon **)((long)ptr2 ^ (long)ptr1);                 \
  153.        ptr1 = (polygon **)((long)ptr1 ^ (long)ptr2);
  154.  
  155. #define median5(v1,v2,v3,v4,v5)                                      \
  156.    if((*v1)->dist < (*v2)->dist){                                    \
  157.       swapPtrs(v1,v2)                                                \
  158.       }                                                              \
  159.    if((*v3)->dist < (*v4)->dist){                                    \
  160.       swapPtrs(v3,v4)                                                \
  161.       }                                                              \
  162.    if((*v1)->dist < (*v3)->dist){                                    \
  163.       swapPtrs(v1,v3)                                                \
  164.       swapPtrs(v2,v4)                                                \
  165.       }                                                              \
  166.    if((*v2)->dist < (*v5)->dist){                                    \
  167.       swapPtrs(v2,v5)                                                \
  168.       }                                                              \
  169.    if((*v2)->dist < (*v3)->dist){                                    \
  170.       swapPtrs(v2,v3)                                                \
  171.       swapPtrs(v4,v5)                                                \
  172.       }                                                              \
  173.    if((*v3)->dist < (*v5)->dist){                                    \
  174.       swapPtrs(v3,v5)                                                \
  175.       }
  176.  
  177.  
  178.  
  179. /* Types */
  180.  
  181.  
  182.  
  183. typedef struct STACKELEMENT{
  184.    int start, end;
  185. } StackElement;
  186.  
  187. typedef struct POINT   point;
  188. typedef struct SEGMENT segment;
  189. typedef struct POLYGON polygon;
  190. typedef struct COLOR_ Color;
  191.  
  192. typedef struct XSEGMENT{
  193.    XPoint P, Q;
  194. } xsegment;
  195.  
  196. struct COLOR_{
  197.    long value;
  198.    long stereoColor;
  199.    int  stipple;
  200.    int red, green, blue;
  201. };
  202.  
  203. struct POINT {
  204.    int ClipFlags;
  205.    int visibility;
  206.    number x,y,z;
  207.    float RX,BX,Y;
  208.    XPoint R;
  209.    short sBX;
  210.    float dist;
  211.    int numSegs;
  212.    segment **segs;
  213.    int numPolys;
  214.    polygon **polys;
  215.    point   *redNext;
  216.    point   *blueNext;
  217. };
  218.  
  219. struct SEGMENT{
  220.    point *P, *Q;
  221.    Color *color;
  222.    int numPolys;
  223.    polygon **polys;
  224. };
  225.  
  226. struct POLYGON{
  227.    segment *m, *n;
  228.    float minDist, maxDist;
  229.    polygon *next;
  230.    float dist;
  231.    int   visibility;
  232.    Color *color;
  233.    int numPoints;
  234.    point **points;
  235.    int numSegs;
  236.    segment **segs;
  237. };
  238.  
  239. typedef struct ANGLEPOINT{
  240.    double x, y, z;
  241. } anglePoint;
  242.  
  243. typedef struct OINFO{
  244.  
  245. /* Geometry information */
  246.  
  247. point   *points;
  248. segment *segs;
  249. polygon *polys;
  250. polygon **list;
  251.  
  252. /* Clipping information */
  253.  
  254. point *bounds;
  255. int  objClip;
  256. int  Hmin, Vmin, Hmax, Vmax;
  257. int  Hmin1, Vmin1, Hmax1, Vmax1;
  258. int  Hmin2, Vmin2, Hmax2, Vmax2;
  259. int  copyX, copyY, copyWidth, copyHeight; 
  260. int  fillX, fillY, fillWidth, fillHeight; 
  261.  
  262. int numPoints, numSegs, numPolys;
  263.  
  264. /* Position information */
  265.  
  266. float tX, tY, tZ, dtX, dtY, dtZ;
  267. float oX, oY, oZ, doX, doY, doZ;
  268. double X, Y, Z,dX, dY, dZ; 
  269. double focus, scale, dscale;
  270. float  BViewpointX, viewpointY;
  271.  
  272. } Oinfo;
  273.  
  274. typedef struct GINFO{
  275.  
  276. /* Position variables */
  277.  
  278. int dpyX, dpyY;
  279. int winX, winY, helpWinX, helpWinY;
  280. int oldPointerX, oldPointerY;
  281.  
  282. /* Font variables */
  283.  
  284. XFontStruct *font, *titleFont, *boldFont;
  285.  
  286. /* flags */
  287.  
  288. int depth, renderMode, buffer, mono, stereo, stereoBlue;
  289. int ColorSelect, Block, Relative, helpMenu, modeChanged;
  290.  
  291. /* Color variables */
  292.  
  293. Color *colors;
  294. int   numColors;
  295. long stereoBlack, redMask, blueMask;
  296.  
  297. /* X window variables */
  298.  
  299. XSegment *redSegments, *blueSegments;
  300. long *redColors;
  301. int numberBlue, numberRed, winH, winV;
  302. int numRedColors;
  303. int requestSize;
  304. long black, white, Black, Red, Blue, Purple;
  305.  
  306. polygon *edgeList;
  307. polygon *freeList;
  308.  
  309. Window   win, helpWin;
  310. Display  *dpy;
  311. Drawable dest;
  312. GC       gc, helpGc;
  313. Colormap colormap;
  314. long red, blue, mask;
  315. XColor cmapColors[3][256];
  316. XColor wireframeColors[2][256];
  317. char *DisplayName, *Geometry;
  318. Pixmap stipple[NUMSTIPPLES], pix;
  319. } Ginfo;
  320.